import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

import { TreeService } from './tree.service';

@Component({
  selector: 'app-tree',
  templateUrl: './tree.component.html',
  styleUrls: ['./tree.component.css']
})

export class TreeComponent implements OnInit {

  @Input() data;
  @Input() isRoot = true;
  @Input() title = "title";
  @Input() children = "children";
  @Output() queryHandle = new EventEmitter();
  @Output() selectHandle = new EventEmitter();

  constructor(
    private treeService: TreeService
  ) { }

  ngOnInit() {
    
  }

  queryData(childData) {
    childData.__spread = !childData.__spread;
    childData[this.children] = [];
    if(childData.__spread) {
      this.queryHandle.emit(childData);
    }
  }

  sendQueryRequest(param) {
    this.queryHandle.emit(param);
  }

  selectData(currentData){
    currentData.__selected = !currentData.__selected;
    this.selectHandle.emit(currentData);
  }

  sendSelectRequest(param) {
    this.selectHandle.emit(param);
  }
}
